package model;

import java.util.ArrayList;
import java.util.List;

public class UserRelationShip {

	private int ID;
	
	private List<User> users;
	private UserRelationState relationStateA;
	private UserRelationState relationStateB;
	
	public enum UserRelationState {
	    OK {
	    	public String toString(){
	    		return "ok";
	    	}
	    }, 
	    BLOCKED{
		    	public String toString(){
		    		return "blocked";
		    	}	
		    }, 
	    RSENT{
	    	public String toString(){
	    		return "request sent";
	    	}	
	    },  
	    RPENDING {
	    	public String toString(){
	    		return "request pending";
	    	}	
	    }  
	}
	
	public UserRelationShip() {
		
		this.users = new ArrayList<User>();
		this.users.add(null);
		this.users.add(null);
		
		setUserA(null);
		setUserB(null);
		relationStateA = null;
		relationStateB = null;
	}

	public UserRelationShip(User userA, UserRelationState relationStateA, User userB, UserRelationState relationStateB) {
		
		this.users = new ArrayList<User>();
		this.users.add(null);
		this.users.add(null);
		
		setUserA(userA);
		setUserB(userB);
		this.relationStateA = relationStateA;
		this.relationStateB = relationStateB;
	}
	
	public int getID() {
		return ID;
	}

	public void setID(int iD) {
		ID = iD;
	}
	
	public User getUserA() {
		return users.get(0);
	}
	private void setUserA(User userA) {
		this.users.set(0, userA);
	}
	public User getUserB() {
		return users.get(1);
	}
	private void setUserB(User userB) {
		this.users.set(1, userB);
	}
	
	public UserRelationState getRelationState(User user) {
		if(getUserA() == user)
			return relationStateA;
		if(getUserB() == user)
			return relationStateB;
		
		return UserRelationState.BLOCKED;
	}
	public void setRelationState(User user, UserRelationState relationState) {
		
		if(getUserA() == user)
			this.relationStateA = relationState;
		if(getUserB() == user)
			this.relationStateB = relationState;
		
	}
	
	public User getBuddyOf(User user) {
		
		if(getUserA() == user)
			return getUserB();
		else
			return getUserA();
	}
	
}
